<?php

/*
Process Token Script (admin_upgrade_tokens.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$points_username = strtolower(ereg_replace(" ", "", $points_username));
$findUsername = fetch("SELECT * FROM members2 WHERE username = '$points_username' AND game = '$game'");

$findTokens = fetch("SELECT * FROM upgrade_tokens WHERE user = '$findUsername[id]' AND game = '$game' AND upgrade = '$tokenType'");
if (!$findTokens[ammount]) { $findTokens[ammount] = 0; }

if ($points_value < 0) { $points_value = 0; }

if ($give_take == "give") { $newAmmount = $findTokens[ammount] + $points_value; $words = "given $points_value $tokenType tokens to"; }

if ($give_take == "take") { $newAmmount = $findTokens[ammount] - $points_value; $words = "taken $points_value $tokenType tokens from"; }

if ($newAmmount <= 0) { $newAmmount = 0; }

if (!$findTokens[id])
{
	mysql_query("INSERT INTO upgrade_tokens (user,game,upgrade,ammount) VALUES ('$findUsername[id]','$game','$tokenType','$newAmmount')");
}
else
{
	mysql_query("UPDATE upgrade_tokens SET ammount=$newAmmount WHERE user = '$findUsername[id]' AND game = '$game' AND upgrade = '$tokenType'");
}

$findTokens2 = fetch("SELECT * FROM upgrade_tokens WHERE user = '$findUsername[id]' AND game = '$game' AND upgrade = '$tokenType'");

$errorMessage = "You+have+$words+$findUsername[display_name],+they+went+from+$findTokens[ammount]+to+$findTokens2[ammount].";

systemmessage("$game", "upgrade_tokens.php?game=$game", "$findUsername[id]", "An admin has $words you!");

header("Location: admin_upgrade_tokens.php?game=$game&error=$errorMessage");

?>
